package com.ruoyi.web.controller.production.fertilizer;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.InjectType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.production.domain.fertilizer.FertilizerPurchaseApply;
import com.ruoyi.production.service.fertilizer.IFertilizerPurchaseApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 化肥购买申请Controller
 *
 * @author ruoyi
 * @date 2021-07-11
 */
@RestController
@RequestMapping("/system/fertilizerApply")
@Api("化肥购买申请")
public class FertilizerPurchaseApplyController extends BaseController
{
    @Autowired
    private IFertilizerPurchaseApplyService fertilizerPurchaseApplyService;

    /**
     * 查询化肥购买申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:fertilizerApply:list')")
    @GetMapping("/list")
    @ApiOperation("查询化肥购买申请列表")
    public TableDataInfo list(FertilizerPurchaseApply fertilizerPurchaseApply)
    {
        startPage();
        List<FertilizerPurchaseApply> list = fertilizerPurchaseApplyService.selectFertilizerPurchaseApplyList(fertilizerPurchaseApply);
        return getDataTable(list);
    }

    /**
     * 导出化肥购买申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:fertilizerApply:export')")
    @Log(title = "化肥购买申请", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FertilizerPurchaseApply fertilizerPurchaseApply)
    {
        List<FertilizerPurchaseApply> list = fertilizerPurchaseApplyService.selectFertilizerPurchaseApplyList(fertilizerPurchaseApply);
        ExcelUtil<FertilizerPurchaseApply> util = new ExcelUtil<FertilizerPurchaseApply>(FertilizerPurchaseApply.class);
        return util.exportExcel(list, "化肥购买申请数据");
    }

    /**
     * 获取化肥购买申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:fertilizerApply:query')")
    @GetMapping(value = "/{fertilizerPurchaseApplyId}")
    public AjaxResult getInfo(@PathVariable("fertilizerPurchaseApplyId") Long fertilizerPurchaseApplyId)
    {
        return AjaxResult.success(fertilizerPurchaseApplyService.selectFertilizerPurchaseApplyById(fertilizerPurchaseApplyId));
    }

    /**
     * 新增化肥购买申请
     */
    @PreAuthorize("@ss.hasPermi('system:fertilizerApply:add')")
    @Log(title = "化肥购买申请", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增化肥购买申请")
    @PropertyInject(type = InjectType.Insert)
    public AjaxResult add(@RequestBody FertilizerPurchaseApply fertilizerPurchaseApply)
    {
        return toAjax(fertilizerPurchaseApplyService.insertFertilizerPurchaseApply(fertilizerPurchaseApply));
    }

    /**
     * 修改化肥购买申请
     */
    @PreAuthorize("@ss.hasAnyPermi('system:fertilizerApply:edit,system:fertilizerApply:permit')")
    @Log(title = "化肥购买申请", businessType = BusinessType.UPDATE)
    @PutMapping
    @PropertyInject(type = InjectType.Update)
    @ApiOperation("修改化肥购买申请")
    public AjaxResult edit(@RequestBody FertilizerPurchaseApply fertilizerPurchaseApply)
    {
        return toAjax(fertilizerPurchaseApplyService.updateFertilizerPurchaseApply(fertilizerPurchaseApply));
    }

    /**
     * 删除化肥购买申请
     */
    @PreAuthorize("@ss.hasPermi('system:fertilizerApply:remove')")
    @Log(title = "化肥购买申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fertilizerPurchaseApplyIds}")
    @ApiOperation("删除化肥购买申请")
    public AjaxResult remove(@PathVariable Long[] fertilizerPurchaseApplyIds)
    {
        return toAjax(fertilizerPurchaseApplyService.deleteFertilizerPurchaseApplyByIds(fertilizerPurchaseApplyIds));
    }
}
